package com.jine.boot7;

import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import com.jine.boot7.servlet.MyServlet;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
@MapperScan("com.jine.boot*.*.mapper")
public class Boot7Application {

    private static final Logger logger = LoggerFactory.getLogger(Boot7Application.class);

    /**
     * 配置fastjson
     * @return
     */
    @Bean
    public HttpMessageConverters initJsonCoverter(){
        FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
        FastJsonConfig fastJsonConfig = new FastJsonConfig();
        fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);
        fastConverter.setFastJsonConfig(fastJsonConfig);
        return new HttpMessageConverters(fastConverter);
    }

    /**
     * 配置MyServlet对应的URL映射路径
     * @return
     */
    @Bean
    public ServletRegistrationBean myServletInit(){
        return new ServletRegistrationBean(new MyServlet(),"/servlet/*");
    }

    public static void main(String[] args) {
        SpringApplication.run(Boot7Application.class, args);
        logger.debug("--Application Started--");
    }
}
